import { Body, Controller, Get, HttpCode, Post } from '@nestjs/common';
import { ApiBody, ApiHeader, ApiProperty, ApiTags } from '@nestjs/swagger';
import { Code } from 'typeorm';
import { PushService } from './push.service';

class SingleDTO {
  @ApiProperty({
    name: 'cid',
    required: true,
    description: '用户的cid',
    default: 'a5f264cf45a044bd4ef441a13dc59349'
  })
  cid: string
}

class HotDTO {
  @ApiProperty({
    name: 'url',
    required: true,
    description: '热更新地址',
    default: ''
  })
  url: string

  @ApiProperty({
    name: 'versionCode',
    required: true,
    description: '版本号',
    default: '100'
  })
  versionCode: number

  @ApiProperty({
    name: 'force',
    required: true,
    description: '强制更新',
    default: false
  })
  force: boolean
}
@Controller('push')
@ApiTags('个推')
export class PushController {
  hotUrl = ''
  force = false
  versionCode = 100
  constructor(
    private readonly pushService: PushService,
  ) {}

  // @Get('token')
  // async getToken() {
  //   return this.pushService.getGetuiToken()
  // }

  @Post('single')
  async pushToSingle(@Body() s: SingleDTO) {
    return this.pushService.pushToSingle(s.cid)
  }

  @Post('all')
  async pushToAll() {
    return this.pushService.pushToAll()
  }

  @Post('setHotUrl')
  async setHotUrl(@Body() obj: HotDTO) {
    this.hotUrl = obj.url
    this.versionCode = obj.versionCode
    this.force = obj.force
    return {
      code: 0,
      data: obj
    }
  }

  @Post('getHotUrl')
  @HttpCode(200)
  async getHotUrl() {
    return {
      code: 0,
      data: {
        url: this.hotUrl,
        versionCode: this.versionCode,
        force: this.force
      }
    }
  }
}
